package com.example.demo.service.Impl;


import com.example.demo.bean.BasePrivilege;
import com.example.demo.bean.BasePrivilegeExample;
import com.example.demo.dao.BasePrivilegeMapper;
import com.example.demo.service.IBasePriviligeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import java.util.List;

@Service

public class BasePriviligeImpl implements IBasePriviligeService {
    @Autowired
    private BasePrivilegeMapper basePrivilegeMapper;

    @Override
    public List<BasePrivilege>query(String name) {
        BasePrivilegeExample example = new BasePrivilegeExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andNameLike("%"+name+"%");

        }
        List<BasePrivilege> list = basePrivilegeMapper.selectByExample(example);
        return list;

    }




    @Override
    public void saveOrUpdate(BasePrivilege basePrivilege) {
       if(basePrivilege.getId()==null){
           basePrivilegeMapper.insert(basePrivilege);
       }
       else{
           basePrivilegeMapper.updateByPrimaryKey(basePrivilege);
       }
    }

    @Override
    public void deleteById(long id) {
      basePrivilegeMapper.deleteByPrimaryKey(id);
    }
}
